<!doctype html>
<html>
	 <head>
	 <meta charset="utf-8">
	 <title>乐享拼购POS核销系统</title>
	 <link rel="shortcut icon" href="{MODULE_URL}app/view/default/admin/favorite.ico" />
	 <link rel="stylesheet" type="text/css" href="{MODULE_URL}app/view/default/admin/css/css.css" />
	 <script type="text/javascript" src="{MODULE_URL}app/view/default/admin/js/jquery.1.11.3.min.js"></script>
	 <script type="text/javascript" src="{MODULE_URL}app/resource/layer/layer.js" ></script>
	 <script type="text/javascript" src="{MODULE_URL}app/view/default/admin/js/jquery.cookie.js"></script>
	 <script type="text/javascript">
	 
	 
function ie8PlaceHolder(){     //to ie8 placeholder
	jQuery('[placeholder]').focus(function() {
  var input = jQuery(this);
  if (input.val() == input.attr('placeholder')) {
    input.val('');
    input.removeClass('placeholder');
  }
}).blur(function() {
  var input = jQuery(this);
  if (input.val() == '' || input.val() == input.attr('placeholder')) {
    input.addClass('placeholder');
    input.val(input.attr('placeholder'));
  }
}).blur().parents('form').submit(function() {
  jQuery(this).find('[placeholder]').each(function() {
    var input = jQuery(this);
    if (input.val() == input.attr('placeholder')) {
      input.val('');
    }
  })
 });
	
}

       function strLoc(){	//get uid	
	    var locatstr=window.location.href;
	    var locs=locatstr.lastIndexOf("=")+1 ;
		var uidstring=locatstr.substr(locs,locatstr.length-locs);
		return uidstring;
		}
	
        function quick_key(){   //弹出快捷键说明层
      	var htmlkey="<div class='quickKey'><p><span>输入订单号 ➤ </span><b>n</b><span>输入手机号 ➤ </span><b>m</b></p><P><span>查询订单号 ➤ </span><b>q</b><span>查询手机号 ➤ </span><b>w</b></p><p><span>核销并打印 ➤ </span><b>F7</b><span>单独打印 ➤ </span><B>F8</B></p><P><span>清空 ➤ </span><b>b</b><span>自动核销 ➤ </span><b>e</b></p><p><span>全屏显示 ➤ </span><b>h</b><span>刷新页面 ➤ </span><b>F5</b></p></div>";
        layer.open({
        title:"快捷键定义说明",
        type: 1,
        skin: 'layui-layer-rim', //加上边框
        area: ['440px', '300px'],
        content:htmlkey
        });
       }
		  
$(function(){
      //设置checkbox状态保存                      	  
	  function checkVal(){
	  var checkobj=$("#writeOff").is(':checked');
	  if(checkobj==true){$.cookie("checkboxValue","true")}
	  else{$.cookie("checkboxValue","false")}
	  }
       
       var checkDef=$("#writeOff")[0];
	   if($.cookie("checkboxValue")=="true"){checkDef.checked="checked"}else{checkDef.checked=""}
	   
     ie8PlaceHolder();
     $("#ddIDtext").focus();
	 function runData(data,n){
		       	var temTable=$(".mallticket ul");
				if(n==0){
				$(".td2").text("");
				$(".ajaxTr").remove();
			  	$("#ddIDtext").val("").focus();
				}else{
				$(".ajaxTr").remove();
				$("#orderno").text(data.orderno);//订单编号
				$("#dispatchtype").text(data.dispatchtype);//配送类型
				if(data.dispatchtype!="自提"){$("#comadd").parents("li").css("display","none");}else{
				$("#comadd").parents("li").removeAttr("style");
				$("#comadd").text(data.comadd);//客选门店
			    }
 				$("#ptime").text(data.ptime);//付款时间
                $("#storename").text(data.storename);  //核销门店
				$("#nickname").text(data.nickname);  //核销员昵称
                $("#hexiaotime").text(data.hexiaotime);//核销时间				               
			   
			    if(data.status=="已完成"){
     		    $("#ptime").parents("li").css("display","none");
				$("#storename").parents("li").removeAttr("style");
				$("#nickname").parents("li").removeAttr("style");
				$("#hexiaotime").parents("li").removeAttr("style");
				}else{
				$("#ptime").parents("li").removeAttr("style");
				$("#storename").parents("li").css("display","none");
				$("#nickname").parents("li").css("display","none");
				$("#hexiaotime").parents("li").css("display","none");
				}
				
				$("#status").text(data.status);//订单状态
				$("#pay_type").text(data.pay_type);//支付方式
				for(var i=0;i<data.params.length;i++){
				var templi="<li class='ajaxTr'><span class='td3'>"+data.params[i].goodsname+"</span><span class='td4'>"+"X"+data.params[i].gnum+"</span></li>";
				$("#goodsList").after(templi);
			      }
		        $("#discount_fee").text(data.discount_fee);//优惠金额
				$("#goodsprice").text(data.goodsprice);//订单金额
				$("#pay_price").text(data.pay_price);//实付金额
				$("#addname").text(data.addname);//收货人
				$("#mobile").text(data.mobile);//手机号
				$("#Remark").text(data.Remark);//备注
				
               } //endif
				return;
				}
			 	
	    
	function orderTo(){
	    var Order_ID=$("#ddIDtext").val().toString(); 
		if(Order_ID==""){layer.msg("订单号码不能为空！");return false;}
	    if($("#writeOff").get(0).checked==""){
	    var Auto_verification=0;}else{Auto_verification=1;}
        unsetKey();
		var index = layer.load(1, {
          shade: [0.6,'#fff'] //0.1透明度的白色背景
         });
	   	   
           $.ajax({
             type: "GET",
             url: "{php echo app_url('admin/list/serch');}",
             data:{"orderno":Order_ID,"Auto_verification":Auto_verification,"uid":strLoc()},
			 dataType: "json",
             success: function(data){
			 layer.close(index);
			 setKey();
			  if(data.statustype==0){
                layer.msg(data.message);
			   }
			   else if(data.statustype==1){
             	runData(data);   //执行写出ajax信息到页面
			    if(data.hexiao==1){printer();}
				if(data.status=="已完成"){layer.msg(data.message);}
			  }
				return;
			  }
         });
  
     }//end irderTo
     
	 function checkMobile(){                              //手机点击查询按钮
		  	  var telNumber=$("#telNumber");
                  if(telNumber.val()==""){layer.msg('手机号码不能为空！');telNumber.focus();return false;}
			      //开始ajax
				 unsetKey();  
				 var index = layer.load(1, {
                 shade: [0.6,'#fff']
               });
                 
				 var telphone=telNumber.val().toString();
				  
		     $.ajax({
             type: "GET",
             url: "{php echo app_url('admin/list/list');}",
             data:{"mobile":telphone,"uid":strLoc()},
			 dataType: "json",
             success: function(data){
			 layer.close(index);			 
			 if(data.statustype==0){
				layer.msg("您输入的手机号码有误，或无相联订单号！");
				setKey();
				return false;
				}
				  var wVal=window.innerWidth;
				  var hVal=window.innerHeight;
				  var hh=hVal/1.5;
				 //开始订单弹出层
				if(wVal>hVal){areaW="600px"}else{areaW="90%"}
				 layer.open({
                      type: 1,
                      area: [areaW,'65%'],
                      shade:0.7,
                      title:"查询手机号：【 "+telNumber.val()+" 】的订单数据", //不显示标题
                      content: $('.orderWinpop'), //捕获的元素
                      cancel: function(index){
				      layer.close(index);
					  telNumber.val("");
                     },
				   success: function(layero,index){
				    for(var i=0;i<data.list.length;i++){
			         $(".orderWinpop table").append("<tr><td><input type='radio' name=orderRadio/></td><td>"+data.list[i].ptime+"</td><td>"+data.list[i].orderno+"</td><td>"+data.list[i].status+"</td></tr>");
			         }
			        //点击后选择 订单输出到页面‘订单查询’框中
					var rAdios=$(".orderWinpop table tr td input[type='radio']");
					for(var i=0;i<rAdios.length;i++){
					rAdios.eq(i).click(function(layero,index){
					$("#ddIDtext").val($(this).parent().next().next().text());	
				    telNumber.val("");	
					setKey();
                	layer.closeAll('page');
					$("#lqdd").click();
					});
					};//end for
					},
				    cancel: function(index){
					  setKey();
					  layer.close(index);
					  } 
									
				   }); 
        		 
				 }//success
               });
			
			}
			
	 function printer(callback){     //打印函数
		    try
            {
                var objfs=new ActiveXObject("Scripting.FileSystemObject");
                var objprinter = objfs.CreateTextFile("LPT1:", true);
			   }catch(Error)
            {
		
                layer.msg("无法获取Active插件，或者LPT1端口未连接打印机。错误信息："+Error.Message);
                return;
            }
	        
			objprinter.Writeline("订单编号："+$("#orderno").text());
			objprinter.Writeline("配送类型："+$("#dispatchtype").text());
			//objprinter.Writeline("客选门店："+$("#comadd").text());
			if($("#ptime").parent().attr("style")!= undefined){
			 objprinter.Writeline("付款时间："+$("#ptime").text());
			}else{
			objprinter.Writeline("核销门店："+$("#storename").text());
			objprinter.Writeline("核销员："+$("#nickname").text());
			objprinter.Writeline("核销时间："+$("#hexiaotime").text());
			}
			
			objprinter.Writeline("支付方式："+$("#pay_type").text());
			objprinter.Writeline("———————————————————————————————");
			objprinter.Writeline("商品信息");
			objprinter.Writeline("———————————————————————————————");
			for(var i=0;i<$(".ajaxTr").length;i++){
			objprinter.Writeline($(".ajaxTr").eq(i).children(".td3").text()+"    "+$(".ajaxTr").eq(i).children(".td4").text());
			}
            objprinter.Writeline("———————————————————————————————");
			objprinter.Writeline("订单金额："+$("#goodsprice").text());
			objprinter.Writeline("优惠金额："+$("#discount_fee").text());
			objprinter.Writeline("实付金额："+$("#pay_price").text());
			objprinter.Writeline("———————————————————————————————");
			objprinter.Writeline("用户信息");
			objprinter.Writeline("———————————————————————————————");
			objprinter.Writeline("用户名："+$("#addname").text());
			objprinter.Writeline("手机号："+$("#mobile").text());
			objprinter.Writeline("备注信息："+$("#Remark").text());
			objprinter.Writeline("********************************");
			objprinter.Writeline("                                ");
			objprinter.Writeline("                                ");
			objprinter.Writeline("                                ");
		    layer.msg("打印完成");
			location.reload();
			callback();
			
		   }
	  
	 function Nuclear_printing(){                       //核销并打印
	 var Order_ID=$("#orderno").text();
	  if(Order_ID==""){
	                  layer.msg("页面无可打印的信息");
					  return;
					  }else{
		 
	   	   unsetKey();
		   
		   $.ajax({
             type: "GET",
             url: "{php echo app_url('admin/list/check');}",
             data:{"orderno":Order_ID,"uid":strLoc()},
			 dataType: "json",
             success: function(data){
			 if(data.statustype==1){
			 printer();
			 }else{layer.msg('已核销订单不能打印');setKey();}
			}
          });
		} //endif
		

	  }
	 
	      function Only_printing(){  	
         
		  //单独打印
		  var Order_ID=$("#orderno").text();
	      if(Order_ID==""){
	                 layer.msg("清空后无法执行此项操作！");
					  return;
					  }else{
	      unsetKey();     	  
	  	 $.ajax({
             type: "GET",
             url: "{php echo app_url('admin/list/print');}",
             data:{"orderno":Order_ID,"uid":strLoc()},
			 dataType: "json",
             success: function(data){
			 printer();
			}
         });
		 
		} //endif
	  }
	  
     function setKey(){
	 $("#lqdd").on("click",orderTo); //点击查询订单号
     $("#seekTel").on("click",checkMobile); //点击查询手机号
	 $("#explain").on("click",quick_key); //点击快捷键说明按钮
	 $("#hxdd").on('click',Nuclear_printing); //点击核销并打印按钮
	 $("#dd").on('click',Only_printing);  //点击单独打印按钮	
	 $("#empty").on('click',function(){runData('',0)}) //点击清空按钮
	 $("#writeOff").on("click",checkVal);
    }
	 
	 setKey(); //第一次加载
	 
	 function unsetKey(){
     $("#lqdd").off("click"); //点击查询订单号
     $("#seekTel").off("click"); //点击查询手机号
	 $("#explain").off("click"); //点击快捷键说明按钮
	 $("#hxdd").off("click"); //点击核销并打印按钮
	 $("#dd").off("click");  //点击单独打印按钮	
	 $("#empty").off("click"); //点击清空按钮
	 // $("#writeOff").off("click");
	}
	
	 $("#ddIDtext").keydown(function(event){   //回车查询订单号
	    if(event.keyCode==13){
		 $("#lqdd").click();
		}
	}); 
	
	$("#telNumber").keydown(function(event){ //回车查询手机号
	     if(event.keyCode==13){
		 $("#seekTel").click();
		}
	}); 
	
    //设置快捷键
	var key_number=0;
	$(document).keydown(function(event){
	    if(event.keyCode == '78'){   //n
		$('#ddIDtext').focus();
		return false;
	    }
	    if(event.keyCode == '77'){   //m
	      $('#telNumber').focus();
		  return false;
	    }
	    if(event.keyCode == '81'){   //q
	        $('#lqdd').click();
			return false;
	    }
	    if(event.keyCode == '87'){    //w
	        $('#seekTel').click();
			return false;
	    }
	    if(event.keyCode == '69'){    //e
	        $('#writeOff').click();
			return false;
	    }
		if(event.keyCode == '66'){     //b
		  	$("#empty").click();
			return false;
		}
		if(event.keyCode == '72'){   //h
		  if($(".quickKey").length==0){$('#explain').click();}
		  return false;
	    }
		if(event.keyCode == '118'){  //f7
	        $('#hxdd').click();
			return false;
	    }
	    if(event.keyCode == '119'){   //f8
 	        $('#dd').click();
			return false;
	    }
	 }); 
	 
       	 
     });// jquery onload

	 </script>
	 </head>

	 <body>

<div id="content">
       <div id="tab">
    <div class="seekDiv fl"> <span>订单编号(N)</span>
           <input id="ddIDtext" type="text" title="请在此框中输入订单号码，然后按回车键或按点击查询按钮。" placeholder="例：20160606849551885396" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')" />
           <a href="javascript:void(0);" id="lqdd" class="buttonStyle fl">查 询(Q)</a> </div>

    <div class="seekDiv fr"> <span>手机号码(M)</span>
           <input type="text" title="请在此框中输入手机号码，然后按回车键或按点击查询按钮。" id="telNumber" placeholder="例：13855556666" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')" />
           <a href="javascript:void(0);" id="seekTel" class="buttonStyle fl">查 询(W)</a> </div>
  </div>
     
      
       <div class="Smallticket">
    <ul id="ul1">
           <li><span class="td1">订单编号：</span><span class="td2" id="orderno"></span></li>
           <li><span class="td1">配送类型：</span><span class="td2" id="dispatchtype"></span></li>
           <li><span class="td1">客选门店：</span><span class="td2" id="comadd"></span></li>
		   <li><span class="td1">付款时间：</span><span class="td2" id="ptime"></span></li>
		   
		   <li><span class="td1">核销门店：</span><span class="td2" id="storename"></span></li>
		   <li><span class="td1">核销员：</span><span class="td2" id="nickname"></span></li>
	       <li><span class="td1">核销时间：</span><span class="td2" id="hexiaotime"></span></li>
  		   
		   
           <li><span class="td1">订单状态：</span><span class="td2" id="status"></span></li>
           <li><span class="td1">支付方式：</span><span class="td2" id="pay_type"></span></li>
           <li>
        <div class="gline"></div>
      </li>
           <li id="goodsList"><span class="td1">✎ 商品信息：</span><span class="td2"></span></li>
           <li><span class="td1">订单金额：</span><span class="td2" id="goodsprice"></span></li>
           <li><span class="td1">优惠金额：</span><span class="td2" id="discount_fee"></span></li>
           <li><span class="td1">实付金额：</span><span class="td2" id="pay_price"></span></li>
           <li>
        <div class="gline"></div>
      </li>
           <li><span class="td1">✎ 用户信息:</span><span class="td2"></span></li>
           <li><span class="td1">用户名：</span><span class="td2" id="addname"></span></li>
           <li><span class="td1">手机号：</span><span class="td2" id="mobile"></span></li>
           <li><span class="td1">✎ 备注：</span><span class="td2" id="Remark"></span></li>
                 
      </ul>
  </div>

     </div>


<div class="buttonGroup">
       <p>
    <input type="checkbox" id="writeOff"/>
    <label for="writeOff" class="hxtext">自动核销(E)</label>
    <a href="javascript:;" id="explain">➥快捷键说明(H)</a></p>
       <p>
    <button id="hxdd">核销并打印（F7）</button>
    <button id="dd">单独打印（F8）</button>
    <button id="empty">清空页面（B）</button>
  </p>
     </div>

<div class="orderWinpop">
       <table>
    <thead>
           <tr>
        <td></td>
        <td>下单时间</td>
		<td>订单状态</td>
        <td>订单编号</td>
      </tr>
         </thead>
  </table>
       <button class="ordersubmit">确 定</button>
     </div>
</body>
</html>
